/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Validator {

    private String value = null;
    private Pattern pattern;
    private Matcher matcher;
    private static final String EMAIL_PATTERN =
            "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
            + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

    public Validator() {
       
    }
 
    /**
     * Validate hex with regular expression
     *
     * @param hex hex for validation
     * @return true valid hex, false invalid hex
     *
     * The combination means, email address must start with “_A-Za-z0-9-\\+” ,
     */
    public boolean validate(final String hex) {
        pattern = Pattern.compile(EMAIL_PATTERN);
        matcher = pattern.matcher(hex);
        return matcher.matches();

    }
 //-------------------------------------------------------------------------
// hiermee wordt er voor u een nieuw wachtwoord gegenereerd dat naar uw e-mail wordt gestuurd.
//-------------------------------------------------------------------------
    public String passRandom(String password) {
        String alphaNumerics = "qwertyuipasdfghjklzxcvbnm123456789";

        for (int i = 0; i < 5; i++) {
            password += alphaNumerics.charAt((int) (Math.random() * alphaNumerics.length()));
        }

        return password;
    }

 //-------------------------------------------------------------------------
//This example keeps only a given set of accepted characters.
//-------------------------------------------------------------------------
    public static String stripGarbage(String s) {
        String good ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        String result = "";
        for (int i = 0; i < s.length(); i++) {
            if (good.indexOf(s.charAt(i)) >= 0) {
                result += s.charAt(i);
            }
        }
        return result;
    }
    //-------------------------------------------------------------------------
    //All phone numbers must in “xx-xxxxxxxx” format. For example
    //-------------------------------------------------------------------------
    public boolean ValidatePhoneNumber(String sPhoneNumber) {
        String PhoneNumber = sPhoneNumber;
        //String sPhoneNumber = "605-88899991";

        // \\d = only digit allow {3} = length
        pattern = Pattern.compile("\\d{2}-\\d{8}");
        matcher = pattern.matcher(PhoneNumber);
        
        return matcher.matches();
    }
        //-------------------------------------------------------------------------
    //All phone numbers must in “xx-xxxxxxxx” format. For example
    //-------------------------------------------------------------------------
    public boolean ValidateTime(String time) {
        String timeNr = time;
        //String sPhoneNumber = "605-88899991";

        // \\d = only digit allow {3} = length
        pattern = Pattern.compile("\\d{2}:\\d{2}:\\d{2}");
        matcher = pattern.matcher(timeNr);
        
        return matcher.matches();
    }
    /*
     public static void main(String[] args) {
     String temp = "Mamadou@.g.nl";
     Validator validator = new Validator();
     boolean valid = emailValidator.validate(temp);
     System.out.println("Email is valid : " + temp + " , " + valid);
     * 
     System.out.println
     (validator.stripGarbage("A good String"));
     System.out.println
     (StringUtils.stripGarbage("String with !%garbage &*("));
     * 
     }
     */
}